home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 453_01 / EXAMPLES / DISCAT / DISCAT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-27  |  2.7 KB  |  104 lines

  1. //    discat.cpp  -  disk catalog sample code  -  1.2
  2. //
  3. //    This is a part of the MetaKit library.
  4. //    Copyright (c) 1996 Meta Four Software.
  5. //    All rights reserved.
  6. /////////////////////////////////////////////////////////////////////////////
  7.  
  8. #include "stdafx.h"
  9. #include "discat.h"
  10. #include "catalog.h"
  11.  
  12. CMyApp ThisApp;        // the global application object
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CMyApp
  16.  
  17. BOOL CMyApp::InitInstance()
  18. {
  19.     CMainDlgWindow mainDlg;
  20.     m_pMainWnd = &mainDlg;
  21.     mainDlg.DoModal();
  22.  
  23.     return FALSE;
  24. }
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CMainDlgWindow
  28.  
  29. BEGIN_MESSAGE_MAP(CMainDlgWindow, CDialog)
  30.     //{{AFX_MSG_MAP(CMainDlgWindow)
  31.     ON_BN_CLICKED(IDC_SCAN_BTN, OnScanBtn)
  32.     //}}AFX_MSG_MAP
  33. END_MESSAGE_MAP()
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36.  
  37. CMainDlgWindow::CMainDlgWindow()
  38.     : CDialog (CMainDlgWindow::IDD)
  39. {
  40.     //{{AFX_DATA_INIT(CMainDlgWindow)
  41.     //}}AFX_DATA_INIT
  42. }
  43.  
  44. void CMainDlgWindow::DoDataExchange(CDataExchange* pDX)
  45. {
  46.     CDialog::DoDataExchange(pDX);
  47.     //{{AFX_DATA_MAP(CMainDlgWindow)
  48.     DDX_Control(pDX, IDC_PATH, m_path);
  49.     DDX_Control(pDX, IDC_STATUS, m_status);
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // [JCW]  This code added for MetaKit DISCAT
  55.  
  56. BOOL CMainDlgWindow::OnInitDialog() 
  57. {
  58.     CDialog::OnInitDialog();
  59.  
  60.         // use the application directory as the default scan path
  61.     CString appDir = ThisApp.m_pszHelpFilePath;
  62.     int n = appDir.ReverseFind('\\');
  63.     if (n >= 0)
  64.         m_path.SetWindowText(appDir.Left(n));
  65.     
  66.     return TRUE;  // return TRUE unless you set the focus to a control
  67. }
  68.  
  69. void CMainDlgWindow::OnScanBtn() 
  70. {
  71.         // find out which directory we should scan
  72.     CString path;
  73.     m_path.GetWindowText(path);
  74.     if (path.Right(1) == '\\')
  75.         path = path.Left(path.GetLength() - 1);
  76.  
  77.         // indicate what is going on
  78.     m_status.SetWindowText("Scanning, please wait...");
  79.  
  80.         // scan the directory tree, see CATALOG.CPP
  81.     c4_View dirs = fScanDirectories(path);
  82.     
  83.         // show what happened
  84.     char buf [30];
  85.     wsprintf(buf, "%d directories were scanned.", dirs.GetSize());
  86.     m_status.SetWindowText(buf);
  87.     
  88.         // save results to file
  89.     CFileDialog dlg (FALSE, NULL, "dirs");
  90.     if (dlg.DoModal() == IDOK)
  91.     {
  92. #if 1
  93.         #define dFormat "dirs[parent:I,name:S,files[name:S,size:I,date:I]]"
  94.         c4_Storage storage (dlg.GetPathName(), dFormat);
  95. #else
  96.         c4_Storage storage (dlg.GetPathName());
  97. #endif
  98.         storage.Set("dirs", dirs);
  99.         storage.Commit();
  100.     }
  101. }  
  102.  
  103. /////////////////////////////////////////////////////////////////////////////
  104.